package com.woniuxy.boot.nb_auth.controller.jwt;

import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTUtil;

import com.woniuxy.boot.common.pojo.ResponseResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("jwt")
public class JwtController {
    @Value("${jwt.secretKey}")
    private String secretKey;

    @GetMapping("verifyJwt")
    public ResponseResult<Void> verifyJwt(@RequestParam("token") String token) {
        boolean isValid = false;
        try {
            isValid = JWTUtil.verify(token, secretKey.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (isValid) {
            return ResponseResult.SUCCESS;
        } else {
            return ResponseResult.FAIL;
        }
    }
}
